package com.maomao.maomaochong_i.zhuye.ReceiveFactory;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;

import com.maomao.maomaochong_i.R;
import com.maomao.maomaochong_i.adapterPackage.MyAdapter;
import com.maomao.maomaochong_i.dataBean.GridItem;
import com.maomao.maomaochong_i.global.Show;
import com.maomao.maomaochong_i.quanxing.Adpater.BrandNewAdapter;
import com.maomao.maomaochong_i.quanxing.Adpater.InterestinProductAdapter;
import com.maomao.maomaochong_i.quanxing.Adpater.PhoneaccessoriesAdapter;
import com.maomao.maomaochong_i.quanxing.Adpater.SecondPhoneAdpter;
import com.maomao.maomaochong_i.quanxing.ShanPingShuJu;

import java.util.ArrayList;

/**
 * Created by Mrma on 17.5.25.
 */

class NeiRong {


    private ArrayList<ShanPingShuJu> list = new ArrayList<>();

    private void get(){
        list.clear();
        switch (show){
            case NEWPHONE:
                list = BrandNewAdapter.getOne().getGetlist();
                break;
            case SENCONEDPHOE:
                list = SecondPhoneAdpter.getOne().getGetlist();
                break;
            case INTERESSTION:
                list = InterestinProductAdapter.getOne().getGetlist();
                break;
            case PHONEACCESSORIES:
                list = PhoneaccessoriesAdapter.getOne().getGetlist();
                break;
        }

    }



    private LayoutInflater inflate;
    private ViewGroup container;
    private Show show;

    /**
     *
     * @param inflater
     * @param container
     * @param show 要跳转的数据类型
     */
    NeiRong(LayoutInflater inflater, ViewGroup container,Show show){
        this.container = container;
        this.inflate = inflater;
        this.show = show;
        get();
        openXian();

    }
    static int YEMian;

    private void openXian(){
        View my = inflate.inflate(YEMian,container,true);
        GridView grid = (GridView) my.findViewById(R.id.xianshi);
        ArrayList<GridItem> mData = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            mData.add(new GridItem(list.get(i).getTu(),
                    list.get(i).getBiao(),
                    list.get(i).getJiage()
            ));

        }


        BaseAdapter mAdapter = new MyAdapter<GridItem>(mData, R.layout.grid) {
            public void bindView(ViewHolder holder, GridItem obj) {
                holder.setImageResource(R.id.getImage, obj.getId());
                holder.setText(R.id.getText, obj.getName());
                holder.setText(R.id.setText, obj.getJiange());
            }
        };
        grid.setAdapter(mAdapter);
    }

}
